#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e5 + 10;
ll a[N];
ll n;
void solve()
{
    cin >> n;
    for (ll i = 1; i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    ll _add = 0, _sub = 0;
    for (ll i = 1; i <= n;i++)
    {
        if(a[i]!=i&&a[i]<=i)
        {
            _add += abs(a[i] - i);
        }
        else 
        {
            _sub += abs(a[i] - i);
        }
    }
    if(_add==_sub)
    {
        cout << _add;
    }
    else
        cout << -1 << endl;
}
int main()
{
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}